package cn.deschen.common.api;

import java.io.Serializable;


/**
 * @Author hanbin_chen
 * @Description 通用操作码
 * @DateTime 2021/6/1
 * @Version 1.0.0
 */
public enum CmResCode implements IResCode, Serializable {

    SUCCESS(200, "操作成功"),

    UNAUTHORIZED(401, "暂未登录或token已经过期"),

    FORBIDDEN(403, "没有相关权限"),

    BIND_ERROR(40, "参数校验异常"),


    SYSTEM_ERROR(500, "系统异常"),

    REPEAT_OPERATION(1121, "请勿重复操作"),

    DATA_NOT_FOUND(1122, "该数据不存在") {
        @Override
        public IResCode fillArgs(Object... msgs) {
            Integer code = this.getCode();

            String message = String.format(
                    this.getMessage().replace("数据", "%s"),
                    msgs);

            return new IResCode() {
                @Override
                public Integer getCode() {
                    return code;
                }

                @Override
                public String getMessage() {
                    return message;
                }
            };
        }
    },

    ;



    private Integer code;
    private String message;

    CmResCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

}
